package com.cn.controller.dz;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.cn.controller.BaseServlet;
import com.cn.service.LoginContrl;

@WebServlet("/login")
public class Login extends BaseServlet {
	private LoginContrl lc;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		forward("dz_/login");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			String phon =req.getParameter("login_name");
			String pw =req.getParameter("login_pw");
			lc = new LoginContrl();
			String pww = lc.getPw(phon);
			if(pw.equals(pww)){
				String name = lc.getname(phon);
				req.getSession().setAttribute("name", name);
				req.removeAttribute("flag");
				forward("dz_/dz");
			}else{
				req.setAttribute("flag", true);
				doGet(req,resp);
			}
	}
}
